package estsapp.utiles.jpanels;



import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.JDesktopPane;

/**
 *
 * @author diego
 */
public class JDesktopPaneConFondo extends JDesktopPane{
    private Image backImage = null; //member variable

   public JDesktopPaneConFondo(String imagePath)
   {
      try
      {
         backImage = new javax.swing.ImageIcon(imagePath).getImage();
      }
      catch(Exception e)
      {
         System.out.println("Could not find file in folder: " + this.getClass().getResource("."));
      }

   }

   public void paintComponent( Graphics g )
   {
      if(backImage == null)
         super.paintComponent(g);
      else
      {
         Graphics2D g2d = (Graphics2D)g;

         //scale the image to fit the size of the Panel
         double mw = backImage.getWidth(null);
         double mh = backImage.getHeight(null);

         double sw = getWidth() / mw;
         double sh = getHeight() / mh;

         //g2d.scale(sw, sh);
         g2d.drawImage(backImage, 0, 0, this);
      }
   }

}
